//
//  FKInformationDetailVC.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/18.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKInformationDetailVC.h"


@interface FKInformationDetailVC ()<UIWebViewDelegate>

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *dateLabel;
@property (nonatomic, weak) UIWebView *webView;

@end

@implementation FKInformationDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"详情";
    self.view.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustBoldFont(20) textColor:fkColor333333];
    [self.view addSubview:titleLabel];
    self.titleLabel = titleLabel;
    titleLabel.numberOfLines = 0;
    
    UILabel *dateLabel = [UILabel fk_labelWithFont:fk_adjustFont(12) textColor:fkColor333333];
    [self.view addSubview:dateLabel];
    self.dateLabel = dateLabel;
    
    UIWebView *webView = [[UIWebView alloc] init];
    [self.view addSubview:webView];
    self.webView = webView;
    webView.delegate = self;
//    webView.scalesPageToFit = true;
    webView.backgroundColor = [UIColor whiteColor];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(12);
        make.right.offset(-12);
        make.top.offset(fk_adjustW(15));
    }];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleLabel);
        make.top.equalTo(titleLabel.mas_bottom).offset(fk_adjustW(12));
    }];
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dateLabel.mas_bottom).offset(fk_adjustW(15));
        make.left.bottom.right.offset(0);
    }];
    
    [self loadData];
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"FKInformationDetailVC.js" ofType:nil];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSString *jsStr = [data mj_JSONString];
    [webView stringByEvaluatingJavaScriptFromString:jsStr];
}

#pragma mark - 网络请求
- (void)loadData
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"article_id"] = self.articleId;
    [SVProgressHUD show];
    [FKHttpTool postWithSuffix:@"m=Home&c=Index&a=new_detail" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            [SVProgressHUD dismiss];
            NSDictionary *detail = result.data[@"detail"];
            self.titleLabel.text = detail[@"title"];
            self.dateLabel.text = fkFORMAT(@"时间:%@  阅读:%@人  来源:%@",  [detail[@"add_time"] fk_timeWithFormat:@"yyyy-MM-dd"], detail[@"hits"], detail[@"source"]);
            
            [self.webView loadHTMLString:detail[@"info"] baseURL:nil];
        }
    } failure:nil];
}



@end
